package com.css.dzj.zfjg.modules.taskinfo.service.impl;


import com.css.dzj.zfjg.common.exception.CvaException;
import com.css.dzj.zfjg.common.util.*;
import com.css.dzj.zfjg.modules.admforce.entity.JgJgxwForceActionEntity;
import com.css.dzj.zfjg.modules.admforce.mapper.ForceMapper;
import com.css.dzj.zfjg.modules.adminspection.entity.JgJgxwCheckActionEntity;
import com.css.dzj.zfjg.modules.adminspection.mapper.checkMapper;
import com.css.dzj.zfjg.modules.admpunishment.entity.JgJgxwPunishActionEntity;
import com.css.dzj.zfjg.modules.admpunishment.mapper.LhjgXwMapper;
import com.css.dzj.zfjg.modules.cohostrelate.entity.QJgLhjgRwxbglbEntity;
import com.css.dzj.zfjg.modules.cohostrelate.mapper.RwxbglbMapper;
import com.css.dzj.zfjg.modules.cohostrelate.service.JgLhjgRwxbglbService;
import com.css.dzj.zfjg.modules.fb.entity.QJgFbLhjgEntity;
import com.css.dzj.zfjg.modules.fb.mapper.JgFbLhjgMapper;
import com.css.dzj.zfjg.modules.feedback.entity.JgLhjgDffkEntity;
import com.css.dzj.zfjg.modules.feedback.entity.QJgLhjgDffkEntity;
import com.css.dzj.zfjg.modules.feedback.mapper.JgLhjgDffkMapper;
import com.css.dzj.zfjg.modules.feedback.service.JgLhjgDffkService;
import com.css.dzj.zfjg.modules.feedbackrelate.Service.JgLhjgRwfkglService;
import com.css.dzj.zfjg.modules.feedbackrelate.entity.JgLhjgRwfkglEntity;
import com.css.dzj.zfjg.modules.feedbackrelate.mapper.LhjgRwfkglMapper;
import com.css.dzj.zfjg.modules.jcdx.entity.JgLhjgJcdxEntity;
import com.css.dzj.zfjg.modules.jcdx.entity.QJgLhjgJcdxEntity;
import com.css.dzj.zfjg.modules.cohostrelate.entity.JgLhjgRwxbglbEntity;
import com.css.dzj.zfjg.modules.fb.entity.JgFbLhjgEntity;
import com.css.dzj.zfjg.modules.fb.service.JgFbLhjgService;
import com.css.dzj.zfjg.modules.jcdx.mapper.JgLhjgJcdxMapper;
import com.css.dzj.zfjg.modules.jcdx.service.JgLhjgJcdxService;
import com.css.dzj.zfjg.modules.other.entity.JgJgxwOtherActionEntity;
import com.css.dzj.zfjg.modules.other.mapper.JgJgxwOtherActionMapper;
import com.css.dzj.zfjg.modules.taskinfo.entity.JgLhjgRwsEntity;
import com.css.dzj.zfjg.modules.taskinfo.entity.QJgLhjgRwsEntity;
import com.css.dzj.zfjg.modules.taskinfo.entity.rwblVo;
import com.css.dzj.zfjg.modules.taskinfo.mapper.JgLhjgRwsMapper;
import com.css.dzj.zfjg.modules.taskinfo.service.JgLhjgRwsService;
import com.css.dzj.zfjg.modules.taskinfo.vo.RwjgLhfb;
import com.css.dzj.zfjg.modules.taskinfo.vo.RwsFqrVo;
import com.querydsl.core.QueryResults;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.apache.poi.ss.formula.functions.Count;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;

import java.util.List;

/**
 * 任务办理实现层
 * @author wt
 * @date 2020\2\20 0020
 */
@Service
public class JgLhjgRwsServiceImpl implements JgLhjgRwsService {


    @Autowired
    private JgLhjgRwsMapper jMapper;

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    @Autowired
    private ServiceUtil serviceUtil;

    @Autowired
    private  HttpServletRequest request;


    @Autowired
    private JgFbLhjgService fbLhjgService;

    @Autowired
    private JgFbLhjgService jgFbLhjgService;
    @Autowired
    private JgFbLhjgMapper fbLhjgMapper;
    @Autowired
    private JgLhjgDffkMapper jgLhjgDffkMapper;
    @Autowired
    private checkMapper kMapper;
    @Autowired
    private LhjgXwMapper lhjgXwMapper;
    @Autowired
    private ForceMapper fMapper;
    @Autowired
    private JgJgxwOtherActionMapper otherActionMapper;
    @Autowired
    private LhjgRwfkglMapper lhjgRwfkglMapper;
    @Autowired
    private JgLhjgJcdxMapper jgLhjgJcdxMapper;
    @Autowired
    private RwxbglbMapper rwxbglbMapper;
    @Autowired
    private JgLhjgRwxbglbService jgLhjgRwxbglbService;
    @Autowired
    private JgLhjgJcdxService jgLhjgJcdxService;
    @Autowired
    private JgLhjgDffkService jgLhjgDffkService;

    @Autowired
    private JgLhjgRwfkglService jgLhjgRwfkglService;



    /**
     * 添加任务书信息
     */
    @Override
    @Transactional
    public void create(JgLhjgRwsEntity jgLhjgRws, JgLhjgJcdxEntity jgLhjgJcdxEntity, List<JgLhjgRwxbglbEntity> jgLhjgRwxbglbEntityList,JgJgxwCheckActionEntity jgJgxwCheckActionEntity,JgJgxwPunishActionEntity jgJgxwPunishActionEntity,JgJgxwForceActionEntity jgJgxwForceActionEntity,JgJgxwOtherActionEntity jgJgxwOtherActionEntity) throws CvaException {
        jMapper.save(jgLhjgRws);
        jgLhjgJcdxEntity.setTaskno(jgLhjgRws.getTaskno());
        jgLhjgJcdxMapper.save(jgLhjgJcdxEntity);
        for (JgLhjgRwxbglbEntity jgLhjgRwxbglbEntity:jgLhjgRwxbglbEntityList) {
            jgLhjgRwxbglbEntity.setTaskNo(jgLhjgRws.getTaskno());
            rwxbglbMapper.save(jgLhjgRwxbglbEntity);
        }
        String taskNo = jgLhjgRws.getTaskno();
        //行政检查
        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null){
           // jgJgxwCheckActionEntity.setCheckActionCode(taskNo.substring(taskNo.length()-3));
            jgJgxwCheckActionEntity.setId(SnowflakeId.getId());
            jgJgxwCheckActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            kMapper.save(jgJgxwCheckActionEntity);
        }

        //行政处罚
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null){
          //  jgJgxwPunishActionEntity.setPunishActionCode(taskNo.substring(taskNo.length()-3));
            jgJgxwPunishActionEntity.setId(SnowflakeId.getId());
            jgJgxwPunishActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            lhjgXwMapper.save(jgJgxwPunishActionEntity);
        }


        //行政强制
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null){
          //  jgJgxwForceActionEntity.setForceActionCode(taskNo.substring(taskNo.length()-3));
            jgJgxwForceActionEntity.setId(SnowflakeId.getId());
            jgJgxwForceActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            fMapper.save(jgJgxwForceActionEntity);
        }


        //其他行为
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null){
          //  jgJgxwOtherActionEntity.setCheckBehaviorNumber(taskNo.substring(taskNo.length()-3));
            jgJgxwOtherActionEntity.setId(SnowflakeId.getId());
            jgJgxwOtherActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            otherActionMapper.save(jgJgxwOtherActionEntity);
        }


        //检查行为表的关联表的记录
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity0 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity1 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity2 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity3 = new JgLhjgRwfkglEntity();

        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null) {
            jgLhjgRwfkglEntity0.setActionId(jgJgxwCheckActionEntity.getId());
            jgLhjgRwfkglEntity0.setSuperviseItemCode("1");
            jgLhjgRwfkglEntity0.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity0);
        }
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null) {
            jgLhjgRwfkglEntity1.setActionId(jgJgxwPunishActionEntity.getId());
            jgLhjgRwfkglEntity1.setSuperviseItemCode("2");
            jgLhjgRwfkglEntity1.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity1);
        }
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null) {
            jgLhjgRwfkglEntity2.setActionId(jgJgxwForceActionEntity.getId());
            jgLhjgRwfkglEntity2.setSuperviseItemCode("3");
            jgLhjgRwfkglEntity2.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity2);
        }
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null) {
            jgLhjgRwfkglEntity3.setActionId(jgJgxwOtherActionEntity.getId());
            jgLhjgRwfkglEntity3.setSuperviseItemCode("4");
            jgLhjgRwfkglEntity3.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity3);
        }
    }

    /**
     * 修改行任务书信息
     */
    @Override
    @Transactional
    public void update(JgLhjgRwsEntity jgLhjgRwsEntity) {

    }

    /**
     * 通过id查询任务书信息
     */
    @Override
    public JgLhjgRwsEntity findById(String taskId) {
        if(StringUtils.isEmpty(taskId)){

            throw new RuntimeException("参数为空");
        }
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory
                .selectFrom(qEntity)
                .where(  qEntity.taskId.eq(taskId),
                        qEntity.delFlag.eq(Constant.NO_DELETE)
                )
                .fetchOne();
    }

    /**
     * 通过taskno查询任务书信息
     */
    @Override
    public JgLhjgRwsEntity findNo(String taskno) {
        if(StringUtils.isEmpty(taskno)){

            throw new RuntimeException("参数为空");
        }
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory
                .selectFrom(qEntity)
                .where(  qEntity.taskno.eq(taskno),
                        qEntity.delFlag.eq(Constant.NO_DELETE)
                )
                .fetchOne();
    }

    /**
     * 分页查询任务书信息
     *
     */
    @Override
    public QueryResults<RwjgLhfb> queryPage(Pageable pageable, String taskname, String taskJgType, String objectname, String fbBureau, String fbDepartment, String createStartTime, String createEndTime, String receiveStartTime, String receiveEndTime, String taskState) {
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        //监管对象表
        QJgLhjgJcdxEntity dEntity = QJgLhjgJcdxEntity.jgLhjgJcdxEntity;
        //协办表
        QJgLhjgRwxbglbEntity bEntity = QJgLhjgRwxbglbEntity.jgLhjgRwxbglbEntity;
        //分办表
        QJgFbLhjgEntity fbEntity = QJgFbLhjgEntity.jgFbLhjgEntity;

        Predicate predicate = qEntity.isNotNull().or(qEntity.isNull());
        predicate = ("".equals(taskname) || taskname == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskname.like("%"+taskname+"%"));
        predicate = ("".equals(taskJgType) || taskJgType == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskJgType.like("%"+taskJgType+"%"));
        predicate = ("".equals(objectname) || objectname == null) ? predicate : ExpressionUtils.and(predicate, dEntity.objectname.like("%"+objectname+"%"));
        predicate = ("".equals(fbBureau) || fbBureau == null) ? predicate : ExpressionUtils.and(predicate, fbEntity.fbBureau.like("%"+fbBureau+"%"));
        predicate = ("".equals(fbDepartment) || fbDepartment == null) ? predicate : ExpressionUtils.and(predicate, fbEntity.fbDepartment.like("%"+fbDepartment+"%"));

        predicate = ("".equals(taskState) || taskState == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskState.eq(taskState));

        /** 任务发起时间 updated by liyuan **/
        if((StringUtils.isEmpty(createStartTime)) && (!StringUtils.isEmpty(createEndTime))) {
            Date endDate=null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(createEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //查询小于等于当前日期
            predicate = ExpressionUtils.and(predicate, qEntity.taskstarttime.loe(endDate));
        }
        if ((!StringUtils.isEmpty(createStartTime)) && (StringUtils.isEmpty(createEndTime))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(createStartTime+" "+"00:00:00.000");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //查询大于等于当前日期
            predicate = ExpressionUtils.and(predicate, qEntity.taskstarttime.goe(startDate));
        }
        if ((!StringUtils.isEmpty(createStartTime)) && (!StringUtils.isEmpty(createEndTime))) {
            Date startDate = null;
            Date endDate=null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(createStartTime+" "+"00:00:00.000");
                endDate = sf.parse(createEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qEntity.taskstarttime.between(startDate, endDate));
        }
        //任务接受时间
        if((StringUtils.isEmpty(receiveStartTime)) && (!StringUtils.isEmpty(receiveEndTime))) {
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(receiveEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, fbEntity.receiveTime.loe(endDate));
        }
        if ((!StringUtils.isEmpty(receiveStartTime)) && (StringUtils.isEmpty(receiveEndTime))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(receiveStartTime+" "+"00:00:00.000");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, fbEntity.receiveTime.goe(startDate));
        }
        if ((!StringUtils.isEmpty(receiveStartTime)) && (!StringUtils.isEmpty(receiveEndTime))) {
            Date startDate = null;
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(receiveStartTime+" "+"00:00:00.000");
                endDate = sf.parse(receiveEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, fbEntity.receiveTime.between(startDate, endDate));
        }


        predicate = ExpressionUtils.and(predicate, qEntity.taskType.eq("0"));
        predicate = ExpressionUtils.and(predicate, qEntity.delFlag.eq(Constant.NO_DELETE)) ;

        return jpaQueryFactory
                .select(
                        Projections.bean(RwjgLhfb.class,
                                qEntity.taskId,qEntity.taskname,qEntity.taskno,qEntity.taskJgType,dEntity.objectname,qEntity.unionSectionName,fbEntity.fbBureau,fbEntity.fbDepartment,qEntity.taskstarttime,qEntity.createTime,fbEntity.receiveTime,qEntity.taskState))
                .from(qEntity)
                .leftJoin(dEntity).on(qEntity.taskno.eq(dEntity.taskno))
              //  .leftJoin(bEntity).on(qEntity.taskno.eq(bEntity.taskNo))
                .leftJoin(fbEntity).on(qEntity.taskno.eq(fbEntity.taskCode))
                .where(predicate)
                .orderBy(qEntity.createTime.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();

    }

    /**
     * 删除任务书信息
     */
    @Override
    @Transactional
    public Boolean delete(String taskId) {
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        if(StringUtils.isEmpty(taskId)){
            return  false;
        }
        try{
            jpaQueryFactory
                    .update(qEntity)
                    .set(qEntity.delFlag,Constant.DELETE)
                    .where(
                            qEntity.delFlag.eq(Constant.NO_DELETE),
                            qEntity.taskId.eq(taskId)
                    )
                    .execute();
            return true;
        }catch (Exception e){
            return false;
        }
    }



    @Override
    public List<JgLhjgRwxbglbEntity> queryXBInfoById(String taskno) {
        QJgLhjgRwxbglbEntity q = QJgLhjgRwxbglbEntity.jgLhjgRwxbglbEntity;
        return jpaQueryFactory.selectFrom(q).where(q.taskNo.eq(taskno)).fetch();
    }

    @Transactional
    @Override
    public void assignTask(String taskno, String fbBureau, String fbDepartment, String fbType) throws CvaException {
        if(fbLhjgService.getByTaskno(taskno)!=null){
            // 若有分办信息，修改分办信息
            JgFbLhjgEntity jgFbLhjgEntity1 = fbLhjgService.getByTaskno(taskno);
            jgFbLhjgEntity1.setFbBureau(fbBureau);
            jgFbLhjgEntity1.setFbDepartment(fbDepartment);
            jgFbLhjgEntity1.setFbState(CvaConstants.SUB_TASK_TODO);
            jgFbLhjgEntity1.setFbType(fbType);
            fbLhjgService.save(jgFbLhjgEntity1);
        }else {
            // 若没有，新建发布表
            JgFbLhjgEntity jgFbLhjgEntity = new JgFbLhjgEntity();
            jgFbLhjgEntity.setFbBureau(fbBureau);
            jgFbLhjgEntity.setFbDepartment(fbDepartment);
            jgFbLhjgEntity.setFbState(CvaConstants.SUB_TASK_TODO);
            jgFbLhjgEntity.setFbType(fbType);
            jgFbLhjgEntity.setTaskCode(taskno);
            //未分办进行分办 不需要生成ID，雪花算法会自动生成
            fbLhjgService.save(jgFbLhjgEntity);
        }
        // 更新任务书发布时间与状态
        JgLhjgRwsEntity jgLhjgRwsEntity = findNo(taskno);
//        Date now = Calendar.getInstance().getTime();
        SimpleDateFormat spf = new SimpleDateFormat("yyyy-MM-dd");
       String formatDate  = spf.format(new Date());
      try{
          Date evaluationDate = spf.parse(formatDate);
          jgLhjgRwsEntity.setFbTime(evaluationDate);
      }catch (Exception e){
          e.printStackTrace();
      }
        // 任务书状态改为已分办
        jgLhjgRwsEntity.setTaskState(CvaConstants.TASK_ALLOCATED);
        update(jgLhjgRwsEntity);
    }

    @Override
    public QueryResults<RwsFqrVo> queryFqTaskPage(String taskname, String taskJgtype, String objectName,
                                                  String launchBureau, String launchState, String initiateunitno,
                                                  String taskStartTimeFirst, String taskStartTimeSecond,
                                                  PageRequest pageRequest) {
        QJgLhjgRwsEntity qRws = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        QJgLhjgJcdxEntity qJcdx = QJgLhjgJcdxEntity.jgLhjgJcdxEntity;
        //协办表
        QJgLhjgRwxbglbEntity bEntity = QJgLhjgRwxbglbEntity.jgLhjgRwxbglbEntity;
        //反馈表
        QJgLhjgDffkEntity fkEntity = QJgLhjgDffkEntity.jgLhjgDffkEntity;
        Predicate predicate = qRws.isNotNull().or(qRws.isNull());
        predicate = (taskname == null || taskname.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qRws.taskname.like("%" + taskname + "%"));
        predicate = (taskJgtype == null || taskJgtype.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qRws.taskJgType.like("%" + taskJgtype + "%"));
        predicate = (launchBureau == null || launchBureau.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qRws.launchBureau.eq(launchBureau));
        predicate = (launchState == null || launchState.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qRws.launchState.eq(launchState));
        predicate = (initiateunitno == null || initiateunitno.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qRws.initiateunitno.eq(initiateunitno));
        // date
        if((StringUtils.isEmpty(taskStartTimeFirst)) && (!StringUtils.isEmpty(taskStartTimeSecond))) {
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(taskStartTimeSecond + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qRws.taskstarttime.loe(endDate));
        }
        if ((!StringUtils.isEmpty(taskStartTimeFirst)) && (StringUtils.isEmpty(taskStartTimeSecond))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(taskStartTimeFirst+" "+"00:00:00.000");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qRws.taskstarttime.goe(startDate));
        }
        if ((!StringUtils.isEmpty(taskStartTimeFirst)) && (!StringUtils.isEmpty(taskStartTimeSecond))) {
            Date startDate = null;
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(taskStartTimeFirst+" "+"00:00:00.000");
                endDate = sf.parse(taskStartTimeSecond + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qRws.taskstarttime.between(startDate, endDate));
        }
        // 检查对象条件
        predicate = (objectName == null || objectName.isEmpty()) ? predicate : ExpressionUtils.and(predicate, qJcdx.objectname.like("%" + objectName + "%"));
        predicate = ExpressionUtils.and(predicate, qRws.taskType.eq("1"));
        predicate = ExpressionUtils.and(predicate, qRws.delFlag.eq(CvaConstants.UN_DEL_FLAG));
        QueryResults<RwsFqrVo> results = jpaQueryFactory.select(
                Projections.bean(
                        RwsFqrVo.class,
                        qRws.taskId,qRws.taskname,qRws.taskno, qRws.taskJgType, qJcdx.objectname, qRws.unionSectionName, qRws.launchState,
                        qRws.initiateunitno, qRws.taskstarttime, qRws.taskendtime))
                .from(qRws)
                .leftJoin(qJcdx).on(qRws.taskno.eq(qJcdx.taskno))
                .where(predicate)
                .orderBy(qRws.createTime.desc())
                .offset(pageRequest.getOffset())
                .limit(pageRequest.getPageSize())
                .fetchResults();
        //分页列表
        List<RwsFqrVo> resultsOld = results.getResults();
        //新分页列表
        List<RwsFqrVo> resultsNew = new ArrayList<RwsFqrVo>();
        for (RwsFqrVo rwsFqrVo:resultsOld){
            String fkCountByTaskNo = jgLhjgDffkService.getFkCountByTaskNo(rwsFqrVo.getTaskno());
            String xbCountByTaskNo = jgLhjgRwxbglbService.getXbCountByTaskNo(rwsFqrVo.getTaskno());
            rwsFqrVo.setFkCount(fkCountByTaskNo);
            rwsFqrVo.setXbCount(xbCountByTaskNo);
            resultsNew.add(rwsFqrVo);
        }
        QueryResults<RwsFqrVo> rwsQueryResults = new QueryResults(resultsNew, (long)pageRequest.getPageSize(), pageRequest.getOffset(), results.getTotal());
        return rwsQueryResults;
    }

    @Transactional
    @Override
    public void launch(String taskno)throws CvaException  {
        JgLhjgRwsEntity lhjgRwsEntity = findNo(taskno);

        //准备国办发起接口的参数
        //taskNo 任务编号  fileXML 发送具体内容,XML格式 字符串类型
        String taskNo = lhjgRwsEntity.getTaskno();

        //调国办的接口

        //修改状态
        lhjgRwsEntity.setLaunchState(CvaConstants.NEW_TASK_LANUCH);
        update(lhjgRwsEntity);
    }

    /**
     * 办理人监管任务列表
     * @author wt
     * @date 2020\2\21 0021
     */
    @Override
    public QueryResults<rwblVo> getBlrList(String orgName, String taskname, String taskJgType, String fbStartTime,String fbEndTime, String objectname, String taskState, Pageable pageable) {
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        //监管对象表
        QJgLhjgJcdxEntity dEntity = QJgLhjgJcdxEntity.jgLhjgJcdxEntity;
        //协办表
        QJgLhjgRwxbglbEntity bEntity = QJgLhjgRwxbglbEntity.jgLhjgRwxbglbEntity;

        QJgFbLhjgEntity fbEntity = QJgFbLhjgEntity.jgFbLhjgEntity;

        Predicate predicate = qEntity.isNotNull().or(qEntity.isNull());
        predicate = ("".equals(taskname) || taskname == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskname.like("%"+taskname+"%"));
        predicate = ("".equals(taskJgType) || taskJgType == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskJgType.like("%"+taskJgType+"%"));
        predicate = ("".equals(objectname) || objectname == null) ? predicate : ExpressionUtils.and(predicate, dEntity.objectname.like("%"+objectname+"%"));
        predicate = ("".equals(taskState) || taskState == null) ? predicate : ExpressionUtils.and(predicate, qEntity.taskState.eq(taskState));

        if((StringUtils.isEmpty(fbStartTime)) && (!StringUtils.isEmpty(fbEndTime))) {
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                endDate = sf.parse(fbEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qEntity.fbTime.loe(endDate));
        }
        if ((!StringUtils.isEmpty(fbStartTime)) && (StringUtils.isEmpty(fbEndTime))) {
            Date startDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(fbStartTime+" "+"00:00:00.000");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qEntity.fbTime.goe(startDate));
        }
        if ((!StringUtils.isEmpty(fbStartTime)) && (!StringUtils.isEmpty(fbEndTime))) {
            Date startDate = null;
            Date endDate = null;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            try {
                startDate = sf.parse(fbStartTime+" "+"00:00:00.000");
                endDate = sf.parse(fbEndTime + " "+"23:59:59.999");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            predicate = ExpressionUtils.and(predicate, qEntity.fbTime.between(startDate, endDate));
        }
        predicate = ExpressionUtils.and(predicate, fbEntity.fbBureau.eq(orgName));
        predicate = ExpressionUtils.and(predicate, qEntity.taskType.eq("0"));
        predicate = ExpressionUtils.and(predicate, qEntity.delFlag.eq(Constant.NO_DELETE));


        return jpaQueryFactory
                .select(
                        Projections.bean(rwblVo.class,
                                qEntity.taskId,qEntity.taskname,qEntity.taskJgType,dEntity.objectname,qEntity.taskstarttime,qEntity.endTime,qEntity.fbTime,qEntity.taskState,qEntity.unionSectionName,qEntity.taskno))
                .from(qEntity)
                .leftJoin(dEntity).on(qEntity.taskno.eq(dEntity.taskno))
               // .leftJoin(bEntity).on(qEntity.taskno.eq(bEntity.taskNo))
                .leftJoin(fbEntity).on(qEntity.taskno.eq(fbEntity.taskCode))
                .where(predicate)
                .orderBy(qEntity.createTime.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();

    }
    @Override
    @Transactional
    public void feedBack(String taskno) throws CvaException {
        //修改状态 反馈
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        JgLhjgRwsEntity jgLhjgRwsEntity  = jpaQueryFactory
                .selectFrom(qEntity)
                .where(  qEntity.taskno.eq(taskno),
                        qEntity.delFlag.eq(Constant.NO_DELETE)
                )
                .fetchOne();
        jgLhjgRwsEntity.setTaskState(CvaConstants.TASK_FEED_BACK);
        Date date = new Date();
        jgLhjgRwsEntity.setFkTime(new Date(date.getTime()));
        jMapper.save(jgLhjgRwsEntity);
        //调取分办service方法修改分班表状态
        JgFbLhjgEntity jgFbLhjgEntity = jgFbLhjgService.getByTaskno(taskno);
        jgFbLhjgEntity.setFbState(CvaConstants.SUB_TASK_FEED_BACK);
        fbLhjgMapper.save(jgFbLhjgEntity);
    }

    @Override
    public void end(String taskno) throws CvaException {
        //修改状态 结束
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        JgLhjgRwsEntity jgLhjgRwsEntity  = jpaQueryFactory
                .selectFrom(qEntity)
                .where(  qEntity.taskno.eq(taskno),
                        qEntity.delFlag.eq(Constant.NO_DELETE)
                )
                .fetchOne();
        jgLhjgRwsEntity.setTaskState(CvaConstants.TASK_FINISHED);
        Date date = new Date();
        jgLhjgRwsEntity.setEndTime(new Date(date.getTime()));
        jMapper.save(jgLhjgRwsEntity);
        //调取分办service方法修改分班表状态
        JgFbLhjgEntity jgFbLhjgEntity = jgFbLhjgService.getByTaskno(taskno);
        if(jgFbLhjgEntity != null) {
            jgFbLhjgEntity.setFbState(CvaConstants.SUB_TASK_FINISHED);
            fbLhjgMapper.save(jgFbLhjgEntity);
        }
    }

    @Override
    @Transactional
    public void reply(JgLhjgDffkEntity jgLhjgDffkEntity, JgJgxwCheckActionEntity jgJgxwCheckActionEntity, JgJgxwPunishActionEntity jgJgxwPunishActionEntity, JgJgxwForceActionEntity jgJgxwForceActionEntity, JgJgxwOtherActionEntity jgJgxwOtherActionEntity, HttpServletRequest request) throws Exception {
        //jgLhjgDffkEntity.setUuid(UuidUtil.getUuid());

        Date date = new Date();
        jgLhjgDffkEntity.setCreateTime(new Date(date.getTime()));
        //SysUserEntity user = (SysUserEntity) request.getSession().getAttribute("user");
        //String fbBureau =user.getDepartmentName();
        //jgLhjgDffkEntity.setCreateUser(user.getUserId());//反馈用户
        //jgLhjgDffkEntity.setUnionDeptname(user.getDepartmentName());//反馈单位

        //监管事项
        //String superviseItemCode = ((String [])params.get("superviseItemCode")).toString();
        //jgLhjgDffkEntity.setSuperviseItemCode(superviseItemCode);
        //jgLhjgDffkDao.insert(jgLhjgDffkEntity);
        jgLhjgDffkMapper.save(jgLhjgDffkEntity);


        jgLhjgRwfkglService.deleteFkglAndActionByTaskNo(jgLhjgDffkEntity.getTaskNo());

        //行政检查

//        if (jgJgxwCheckActionEntity != null){
//            //jgJgxwCheckActionEntity.setId(UuidUtil.getUuid());
//            String taskNo = jgLhjgDffkEntity.getTaskNo();
//            jgJgxwCheckActionEntity.setCheckActionCode(taskNo.substring(taskNo.length()-3));
//            kMapper.save(jgJgxwCheckActionEntity);
//        }
        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null){
            if(StringUtils.isEmpty(jgJgxwCheckActionEntity.getId())) {
                jgJgxwCheckActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwCheckActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            String taskNo = jgLhjgDffkEntity.getTaskNo();
            //jgJgxwCheckActionEntity.setCheckActionCode(taskNo.substring(taskNo.length()-3));
            kMapper.save(jgJgxwCheckActionEntity);
        }

        //行政处罚
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null){
            if(StringUtils.isEmpty(jgJgxwPunishActionEntity.getId())) {
                jgJgxwPunishActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwPunishActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            String taskNo = jgLhjgDffkEntity.getTaskNo();
          //  jgJgxwPunishActionEntity.setPunishActionCode(taskNo.substring(taskNo.length()-3));
            //jgJgxwPunishActionDao.insert(jgJgxwPunishActionEntity);
            lhjgXwMapper.save(jgJgxwPunishActionEntity);
        }


        //行政强制
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null){
            if(StringUtils.isEmpty(jgJgxwForceActionEntity.getId())) {
                jgJgxwForceActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwForceActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            String taskNo = jgLhjgDffkEntity.getTaskNo();
           // jgJgxwForceActionEntity.setForceActionCode(taskNo.substring(taskNo.length()-3));
            //jgJgxwForceActionDao.insert(jgJgxwForceActionEntity);
            fMapper.save(jgJgxwForceActionEntity);
        }


        //其他行为
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null){
            if(StringUtils.isEmpty(jgJgxwOtherActionEntity.getId())) {
                jgJgxwOtherActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwOtherActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            String taskNo = jgLhjgDffkEntity.getTaskNo();
            //jgJgxwOtherActionEntity.setCheckBehaviorNumber(taskNo.substring(taskNo.length()-3));
            otherActionMapper.save(jgJgxwOtherActionEntity);
        }


        //答复反馈表和检查行为表的关联表的记录
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity0 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity1 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity2 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity3 = new JgLhjgRwfkglEntity();

        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null){
            jgLhjgRwfkglEntity0.setDffkId(jgLhjgDffkEntity.getUuid());
            jgLhjgRwfkglEntity0.setActionId(jgJgxwCheckActionEntity.getId());
            // jgLhjgRwfkglEntity0.setSuperviseItemCode(jgJgxwCheckActionEntity.getCheckActionCode());
            jgLhjgRwfkglEntity0.setSuperviseItemCode("1");
            jgLhjgRwfkglEntity0.setTaskno(jgLhjgDffkEntity.getTaskNo());
            //jgLhjgRwfkglEntity0.setUuid(UuidUtil.getUuid());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity0);
        }
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null){
            jgLhjgRwfkglEntity1.setDffkId(jgLhjgDffkEntity.getUuid());
            jgLhjgRwfkglEntity1.setActionId(jgJgxwPunishActionEntity.getId());
            // jgLhjgRwfkglEntity1.setSuperviseItemCode(jgJgxwPunishActionEntity.getSuperviseItemCode());
            jgLhjgRwfkglEntity1.setSuperviseItemCode("2");
            jgLhjgRwfkglEntity1.setTaskno(jgLhjgDffkEntity.getTaskNo());
            System.out.println();
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity1);
        }
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null){
            jgLhjgRwfkglEntity2.setDffkId(jgLhjgDffkEntity.getUuid());
            jgLhjgRwfkglEntity2.setActionId(jgJgxwForceActionEntity.getId());
            //jgLhjgRwfkglEntity2.setSuperviseItemCode(jgJgxwForceActionEntity.getSuperviseItemCode());
            jgLhjgRwfkglEntity2.setSuperviseItemCode("3");
            jgLhjgRwfkglEntity2.setTaskno(jgLhjgDffkEntity.getTaskNo());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity2);
        }
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null){
            System.out.println();
            jgLhjgRwfkglEntity3.setDffkId(jgLhjgDffkEntity.getUuid());
            jgLhjgRwfkglEntity3.setActionId(jgJgxwOtherActionEntity.getId());
           // jgLhjgRwfkglEntity3.setSuperviseItemCode(jgJgxwForceActionEntity.getSuperviseItemCode());
            jgLhjgRwfkglEntity3.setSuperviseItemCode("4");
            jgLhjgRwfkglEntity3.setTaskno(jgLhjgDffkEntity.getTaskNo());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity3);
        }

        //保存答复表的附件
        //JgTsjbAccessoryEntity accessoryEntity = new JgTsjbAccessoryEntity();

        /*//获取前端传过来的附件数据并转为一个实体对象
        //JSONObject jsonObject = null;
        jsonObject = JSONObject.parseObject(JSON.toJSONString(params.get("jgTsjbAccessoryEntity")) );
        JgTsjbAccessoryEntity jgTsjbAccessoryEntity = jsonObject.toJavaObject(JgTsjbAccessoryEntity.class);*/

        String file = jgLhjgDffkEntity.getFileUrl();
        /*JgTsjbAccessoryEntity jgTsjbAccessoryEntity = new JgTsjbAccessoryEntity();
        if (  file != null && !"".equals(file)){
            jgTsjbAccessoryEntity.setFilePath(file);
            //对传过来的数据进行处理，返回一个处理后的附件对象
            if (jgTsjbAccessoryEntity != null){
                accessoryEntity =new UploadFile().uploadFile(jgTsjbAccessoryEntity);
                //关联答复ID，并保存
                accessoryEntity.setRegisterCode(jgLhjgDffkEntity.getUuid());
                jgTsjbAccessoryDao.insert(accessoryEntity);
            }
        }*/

        //答复完成，修改任务书和分办表的状态为已答复
        //JgLhjgRwsEntity jgLhjgRwsEntity = jgLhjgRwsDao.getRws(jgLhjgDffkEntity.getTaskNo());
        JgLhjgRwsEntity jgLhjgRwsEntity = findNo(jgLhjgDffkEntity.getTaskNo());
        jgLhjgRwsEntity.setTaskState(CvaConstants.TASK_REPLIES);
        jMapper.save(jgLhjgRwsEntity);
        //jgLhjgRwsDao.updateById(jgLhjgRwsEntity);

        //分办表
        //JgFbLhjgEntity jgFbLhjgEntity = jgFbLhjgDao.getByTaskNo(jgLhjgDffkEntity.getTaskNo());
        JgFbLhjgEntity jgFbLhjgEntity = jgFbLhjgService.getByTaskno(jgLhjgDffkEntity.getTaskNo());
        if (jgFbLhjgEntity != null){
            jgFbLhjgEntity.setFbState(CvaConstants.SUB_TASK_REPLIES);
            //分办表的答复时间
            //Date date = new Date();
            jgFbLhjgEntity.setReplyTime(new Date(date.getTime()));
            //jgFbLhjgDao.updateById(jgFbLhjgEntity);
            fbLhjgMapper.save(jgFbLhjgEntity);
        }
    }

    /**
     * 获取最大任务编码
     * @return
     */
    @Override
    public String getMaxOne() {
        return jMapper.getMaxOne();
    }

    @Override
    @Transactional
    public void updateRwsAndall(JgLhjgRwsEntity jgLhjgRws, JgLhjgJcdxEntity jgLhjgJcdxEntity, List<JgLhjgRwxbglbEntity> jgLhjgRwxbglbEntityList,JgJgxwCheckActionEntity jgJgxwCheckActionEntity,JgJgxwPunishActionEntity jgJgxwPunishActionEntity,JgJgxwForceActionEntity jgJgxwForceActionEntity,JgJgxwOtherActionEntity jgJgxwOtherActionEntity) throws CvaException {
        this.update(jgLhjgRws);

        //删除此任务下的所有协办部门，以最后修改页面呈现的为准
        jgLhjgRwxbglbService.deleteByTaskNo(jgLhjgRws.getTaskno());
        for (JgLhjgRwxbglbEntity jgLhjgRwxbglbEntity:jgLhjgRwxbglbEntityList){
            jgLhjgRwxbglbService.add(jgLhjgRwxbglbEntity,request);
        }
        jgLhjgJcdxService.updateById(jgLhjgJcdxEntity);
        String taskNo = jgLhjgRws.getTaskno();

        jgLhjgRwfkglService.deleteFkglAndActionByTaskNo(taskNo);

        //行政检查
        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null){
            // jgJgxwCheckActionEntity.setCheckActionCode(taskNo.substring(taskNo.length()-3));
            if(StringUtils.isEmpty(jgJgxwCheckActionEntity.getId())) {
                jgJgxwCheckActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwCheckActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            kMapper.save(jgJgxwCheckActionEntity);
        }

        //行政处罚
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null){
            //jgJgxwPunishActionEntity.setPunishActionCode(taskNo.substring(taskNo.length()-3));
            if(StringUtils.isEmpty(jgJgxwPunishActionEntity.getId())) {
                jgJgxwPunishActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwPunishActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            lhjgXwMapper.save(jgJgxwPunishActionEntity);
        }


        //行政强制
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null){
            // jgJgxwForceActionEntity.setForceActionCode(taskNo.substring(taskNo.length()-3));
            if(StringUtils.isEmpty(jgJgxwForceActionEntity.getId())) {
                jgJgxwForceActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwForceActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            fMapper.save(jgJgxwForceActionEntity);
        }


        //其他行为
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null){
            // jgJgxwOtherActionEntity.setCheckBehaviorNumber(taskNo.substring(taskNo.length()-3));
            if(StringUtils.isEmpty(jgJgxwOtherActionEntity.getId())) {
                jgJgxwOtherActionEntity.setId(SnowflakeId.getId());
            }
            jgJgxwOtherActionEntity.setCdOperation(CvaConstants.UN_DELETED_FLAG);
            otherActionMapper.save(jgJgxwOtherActionEntity);
        }


        //检查行为表的关联表的记录
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity0 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity1 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity2 = new JgLhjgRwfkglEntity();
        JgLhjgRwfkglEntity jgLhjgRwfkglEntity3 = new JgLhjgRwfkglEntity();

        if ( "".equals(jgJgxwCheckActionEntity.getCheckActionCode())){

        } else if (jgJgxwCheckActionEntity != null) {
            jgLhjgRwfkglEntity0.setActionId(jgJgxwCheckActionEntity.getId());
            jgLhjgRwfkglEntity0.setSuperviseItemCode("1");
            jgLhjgRwfkglEntity0.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity0);
        }
        if ( "".equals(jgJgxwPunishActionEntity.getPunishActionCode())){

        } else if (jgJgxwPunishActionEntity != null) {
            jgLhjgRwfkglEntity1.setActionId(jgJgxwPunishActionEntity.getId());
            jgLhjgRwfkglEntity1.setSuperviseItemCode("2");
            jgLhjgRwfkglEntity1.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity1);
        }
        if ( "".equals(jgJgxwForceActionEntity.getForceActionCode())){

        } else if (jgJgxwForceActionEntity != null) {
            jgLhjgRwfkglEntity2.setActionId(jgJgxwForceActionEntity.getId());
            jgLhjgRwfkglEntity2.setSuperviseItemCode("3");
            jgLhjgRwfkglEntity2.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity2);
        }
        if ( "".equals(jgJgxwOtherActionEntity.getActionCode())){

        } else if (jgJgxwOtherActionEntity != null) {
            jgLhjgRwfkglEntity3.setActionId(jgJgxwOtherActionEntity.getId());
            jgLhjgRwfkglEntity3.setSuperviseItemCode("4");
            jgLhjgRwfkglEntity3.setTaskno(jgLhjgRws.getTaskno());
            lhjgRwfkglMapper.save(jgLhjgRwfkglEntity3);
        }

    }

    /**
     * 获取单个发起任务
     */
    @Override
    public JgLhjgRwsEntity queryInfoById(String taskno) {
        if(StringUtils.isEmpty(taskno)){

            throw new RuntimeException("参数为空");
        }
        QJgLhjgRwsEntity qEntity  = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory
                .selectFrom(qEntity)
                .where(  qEntity.taskno.eq(taskno),
                        qEntity.delFlag.eq(Constant.NO_DELETE)
                )
                .fetchOne();
    }

    /**
     * 查询认领超时提醒
     * @param pageable
     * @return
     */
    @Override
    public QueryResults<JgLhjgRwsEntity> queryOvertime(Pageable pageable) {
        QJgLhjgRwsEntity q = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory.selectFrom(q)
                .where(q.taskState.eq(CvaConstants.SUB_TASK_URGE))
                .orderBy(q.createTime.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();
    }

    @Override
    public QueryResults<JgLhjgRwsEntity> queryOveramount(Pageable pageable) {
        QJgLhjgRwsEntity q = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory.selectFrom(q)
                .where(q.taskState.eq(CvaConstants.SUB_TASK_REFUSE))
                .orderBy(q.createTime.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();
    }

    /**
     * 查询所有认领超时提醒任务的数量
     * @return
     */
    @Override
    public Long queryOvertimeCount() {
        QJgLhjgRwsEntity q = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory.selectFrom(q)
                .where(q.taskState.eq(CvaConstants.SUB_TASK_URGE))
                .fetchCount();
    }

    /**
     * 查询所有未认领超限任务的数量
     * @return
     */
    @Override
    public Long queryOveramountCount() {
        QJgLhjgRwsEntity q = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        return jpaQueryFactory.selectFrom(q)
                .where(q.taskState.eq(CvaConstants.SUB_TASK_REFUSE))
                .fetchCount();
    }
    /**
     * 查询所有任务书
     * @return 任务书信息List
     */
    @Override
    public List queryAllRws() {
        QJgLhjgRwsEntity q = QJgLhjgRwsEntity.jgLhjgRwsEntity;
        Predicate predicate = q.isNotNull().or(q.isNull());
        predicate = ExpressionUtils.and(predicate, q.delFlag.eq(Constant.NO_DELETE)) ;
        List<JgLhjgRwsEntity> list = jpaQueryFactory.selectFrom(q)
                .where(predicate)
                .orderBy(q.createTime.desc())
                .fetch();
        return list;
    }
}
